#include "TextFont.h"
#include "TextureManager.h"

TextFont::TextFont()
{
	font = nullptr;

	spriteManager = TextureManager::getInstance()->getSpriteManager();
}

TextFont::~TextFont()
{
	SAFE_RELEASE(font);
}

void TextFont::Draw( String Text,const Vector2 &Position,Color color )
{
	Matrix position;
	TranslateMatrix(position,Position.x,Position.y,0);
	spriteManager->SetTransform(&position);
	font->DrawTextA(spriteManager,Text,-1,nullptr,DT_LEFT,color);
}

void TextFont::Draw( int Text,const Vector2 &Position,Color color )
{
	ostringstream oss;
	oss << Text;

	Matrix position;
	TranslateMatrix(position,Position.x,Position.y,0);
	spriteManager->SetTransform(&position);
	font->DrawTextA(spriteManager,oss.str().c_str(),-1,nullptr,DT_LEFT,color);
}

void TextFont::Draw( unsigned Text,const Vector2 &Position,Color color )
{
	ostringstream oss;
	oss << Text;

	Matrix position;
	TranslateMatrix(position,Position.x,Position.y,0);
	spriteManager->SetTransform(&position);
	font->DrawTextA(spriteManager,oss.str().c_str(),-1,nullptr,DT_LEFT,color);
}

void TextFont::Draw( short Text,const Vector2 &Position,Color color )
{
	ostringstream oss;
	oss << Text;

	Matrix position;
	TranslateMatrix(position,Position.x,Position.y,0);
	spriteManager->SetTransform(&position);
	font->DrawTextA(spriteManager,oss.str().c_str(),-1,nullptr,DT_LEFT,color);
}

void TextFont::Draw( unsigned short Text,const Vector2 &Position,Color color )
{
	ostringstream oss;
	oss << Text;

	Matrix position;
	TranslateMatrix(position,Position.x,Position.y,0);
	spriteManager->SetTransform(&position);
	font->DrawTextA(spriteManager,oss.str().c_str(),-1,nullptr,DT_LEFT,color);
}

void TextFont::Draw( float Text,const Vector2 &Position,Color color )
{
	ostringstream oss;
	oss << Text;

	Matrix position;
	TranslateMatrix(position,Position.x,Position.y,0);
	spriteManager->SetTransform(&position);
	font->DrawTextA(spriteManager,oss.str().c_str(),-1,nullptr,DT_LEFT,color);
}

void TextFont::Draw( double Text,const Vector2 &Position,Color color )
{
	ostringstream oss;
	oss << Text;

	Matrix position;
	TranslateMatrix(position,Position.x,Position.y,0);
	spriteManager->SetTransform(&position);
	font->DrawTextA(spriteManager,oss.str().c_str(),-1,nullptr,DT_LEFT,color);
}

void TextFont::Draw( unsigned char Text,const Vector2 &Position,Color color )
{
	ostringstream oss;
	oss << (int)Text;

	Matrix position;
	TranslateMatrix(position,Position.x,Position.y,0);
	spriteManager->SetTransform(&position);
	font->DrawTextA(spriteManager,oss.str().c_str(),-1,nullptr,DT_LEFT,color);
}

void TextFont::Draw( char Text,const Vector2 &Position,Color color )
{
	ostringstream oss;
	oss << (int)Text;

	Matrix position;
	TranslateMatrix(position,Position.x,Position.y,0);
	spriteManager->SetTransform(&position);
	font->DrawTextA(spriteManager,oss.str().c_str(),-1,nullptr,DT_LEFT,color);
}

void TextFont::Draw( long long Text,const Vector2 &Position,Color color )
{
	ostringstream oss;
	oss << Text;

	Matrix position;
	TranslateMatrix(position,Position.x,Position.y,0);
	spriteManager->SetTransform(&position);
	font->DrawTextA(spriteManager,oss.str().c_str(),-1,nullptr,DT_LEFT,color);
}

void TextFont::Draw( unsigned long long Text,const Vector2 &Position,Color color )
{
	ostringstream oss;
	oss << Text;

	Matrix position;
	TranslateMatrix(position,Position.x,Position.y,0);
	spriteManager->SetTransform(&position);
	font->DrawTextA(spriteManager,oss.str().c_str(),-1,nullptr,DT_LEFT,color);
}

void TextFont::Draw( const Vector2 &Text,const Vector2 &Position,Color color )
{
	ostringstream oss;
	oss << "( " << Text.x << ", " << Text.y << " )";

	Matrix position;
	TranslateMatrix(position,Position.x,Position.y,0);
	spriteManager->SetTransform(&position);
	font->DrawTextA(spriteManager,oss.str().c_str(),-1,nullptr,DT_LEFT,color);
}

void TextFont::Draw( const Vector3 &Text,const Vector2 &Position,Color color )
{
	ostringstream oss;
	oss << "( " << Text.x << ", " << Text.y << ", " << Text.z << " )";

	Matrix position;
	TranslateMatrix(position,Position.x,Position.y,0);
	spriteManager->SetTransform(&position);
	font->DrawTextA(spriteManager,oss.str().c_str(),-1,nullptr,DT_LEFT,color);
}

void TextFont::Create( String Font /*= "Times New Roman"*/,unsigned short Size /*= 16*/,const Color &FontColor /*= Color(.9f,.9f,.9f,1)*/ )
{
	SAFE_RELEASE(font);

	D3DXCreateFontA(D3DManager::getInstance()->getDevice(), Size, 0, FW_NORMAL, 0, false, 
		DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, 
		ANTIALIASED_QUALITY, DEFAULT_PITCH | FF_DONTCARE, 
		Font, &font);
}

void TextFont::DrawInRect( String Text,RECT &rect,Color fontColor,Align Alignment)
{
	Matrix transform;
	TranslateMatrix(transform,0,0,0);
	spriteManager->SetTransform(&transform);
	font->DrawTextA(spriteManager,Text,-1,&rect,Alignment,fontColor);
}

void TextFont::DrawInRect( int Text,RECT &rect,Color fontColor,Align Alignment )
{
	ostringstream oss;
	oss << Text;

	Matrix transform;
	TranslateMatrix(transform,0,0,0);
	spriteManager->SetTransform(&transform);

	font->DrawTextA(spriteManager,oss.str().c_str(),-1,&rect,Alignment,fontColor);
}

void TextFont::DrawInRect( unsigned Text,RECT &rect,Color fontColor,Align Alignment )
{
	ostringstream oss;
	oss << Text;

	Matrix transform;
	TranslateMatrix(transform,0,0,0);
	spriteManager->SetTransform(&transform);

	font->DrawTextA(spriteManager,oss.str().c_str(),-1,&rect,Alignment,fontColor);
}

void TextFont::DrawInRect( short Text,RECT &rect,Color fontColor,Align Alignment )
{
	ostringstream oss;
	oss << Text;

	Matrix transform;
	TranslateMatrix(transform,0,0,0);
	spriteManager->SetTransform(&transform);

	font->DrawTextA(spriteManager,oss.str().c_str(),-1,&rect,Alignment,fontColor);
}

void TextFont::DrawInRect( unsigned short Text,RECT &rect,Color fontColor,Align Alignment )
{
	ostringstream oss;
	oss << Text;

	Matrix transform;
	TranslateMatrix(transform,0,0,0);
	spriteManager->SetTransform(&transform);

	font->DrawTextA(spriteManager,oss.str().c_str(),-1,&rect,Alignment,fontColor);
}

void TextFont::DrawInRect( float Text,RECT &rect,Color fontColor,Align Alignment )
{
	ostringstream oss;
	oss << Text;

	Matrix transform;
	TranslateMatrix(transform,0,0,0);
	spriteManager->SetTransform(&transform);

	font->DrawTextA(spriteManager,oss.str().c_str(),-1,&rect,Alignment,fontColor);
}

void TextFont::DrawInRect( double Text,RECT &rect,Color fontColor,Align Alignment )
{
	ostringstream oss;
	oss << Text;

	Matrix transform;
	TranslateMatrix(transform,0,0,0);
	spriteManager->SetTransform(&transform);

	font->DrawTextA(spriteManager,oss.str().c_str(),-1,&rect,Alignment,fontColor);
}

void TextFont::DrawInRect( unsigned char Text,RECT &rect,Color fontColor,Align Alignment )
{
	ostringstream oss;
	oss << (int)Text;

	Matrix transform;
	TranslateMatrix(transform,0,0,0);
	spriteManager->SetTransform(&transform);

	font->DrawTextA(spriteManager,oss.str().c_str(),-1,&rect,Alignment,fontColor);
}

void TextFont::DrawInRect( char Text,RECT &rect,Color fontColor,Align Alignment )
{
	ostringstream oss;
	oss << (int)Text;

	Matrix transform;
	TranslateMatrix(transform,0,0,0);
	spriteManager->SetTransform(&transform);

	font->DrawTextA(spriteManager,oss.str().c_str(),-1,&rect,Alignment,fontColor);
}

void TextFont::DrawInRect( long long Text,RECT &rect,Color fontColor,Align Alignment )
{
	ostringstream oss;
	oss << Text;

	Matrix transform;
	TranslateMatrix(transform,0,0,0);
	spriteManager->SetTransform(&transform);

	font->DrawTextA(spriteManager,oss.str().c_str(),-1,&rect,Alignment,fontColor);
}

void TextFont::DrawInRect( unsigned long long Text,RECT &rect,Color fontColor,Align Alignment )
{
	ostringstream oss;
	oss << Text;

	Matrix transform;
	TranslateMatrix(transform,0,0,0);
	spriteManager->SetTransform(&transform);

	font->DrawTextA(spriteManager,oss.str().c_str(),-1,&rect,Alignment,fontColor);
}

void TextFont::DrawInRect( const Vector2 &Text,RECT &rect,Color fontColor,Align Alignment /*= Center*/ )
{
	ostringstream oss;
	oss << "( " << Text.x << ", " << Text.y << " )";

	Matrix transform;
	TranslateMatrix(transform,0,0,0);
	spriteManager->SetTransform(&transform);

	font->DrawTextA(spriteManager,oss.str().c_str(),-1,&rect,Alignment,fontColor);
}

void TextFont::DrawInRect( const Vector3 &Text,RECT &rect,Color fontColor,Align Alignment /*= Center*/ )
{
	ostringstream oss;
	oss << "( " << Text.x << ", " << Text.y << ", " << Text.z << " )";

	Matrix transform;
	TranslateMatrix(transform,0,0,0);
	spriteManager->SetTransform(&transform);

	font->DrawTextA(spriteManager,oss.str().c_str(),-1,&rect,Alignment,fontColor);
}
